package com.oto.model;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

/**
 * 搜索索引数据
 * 
 * @author xueqiang.mi
 * @since 2011-1-16
 */
@PersistenceCapable(table = "Index", identityType = IdentityType.APPLICATION)
public class IndexDO implements Serializable {
	private static final long serialVersionUID = 6028241712582849L;
	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Long id;
	@Persistent
	private String key;
	@Persistent
	private Set<Long> flows;

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		IndexDO other = (IndexDO) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (key == null) {
			if (other.key != null)
				return false;
		} else if (!key.equals(other.key))
			return false;
		return true;
	}

	public Set<Long> getFlows() {
		if (flows == null) {
			flows = new HashSet<Long>();
		}
		return flows;
	}

	public Long getId() {
		return id;
	}

	public String getKey() {
		return key;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + ((key == null) ? 0 : key.hashCode());
		return result;
	}

	public void setFlows(Set<Long> flows) {
		this.flows = flows;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public void setKey(String key) {
		this.key = key;
	}

	@Override
	public String toString() {
		return "IndexDO [id=" + id + ", key=" + key + ", flows=" + flows + "]";
	}
}
